package com.day1014.remote;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MyPanel extends JPanel {
    BufferedImage image = null;
    ServerSocket serverSocket = null;
    public MyPanel(){
        try {
            serverSocket = new ServerSocket(5555);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void readImage(){
        try {
            while (true){
                Socket socket = serverSocket.accept();
                InputStream inputStream = socket.getInputStream();
                image = ImageIO.read(inputStream);
                repaint();
//                inputStream.close();
//                socket.close();
//                serverSocket.close();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void paint(Graphics g) {
        g.drawImage(image,0,0,1920,1080,null);

    }
}
